package com.xc.sbdemo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api
@Controller
public class HelloController {

    @ApiOperation("Hello Spring Boot 方法")
    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        int num = 1/0;
        return "hello sb";
    }

    @ExceptionHandler(RuntimeException.class)
    public String handle(Exception e, Model model) {
        model.addAttribute("level","局部异常");
        model.addAttribute("errorInfo",e.getMessage());
        return "error";
    }
}
